<template>
  <div class="layout">
    <header class="layout-header">
      <div class="header-content">
        <div style="display: flex; align-items: center">
          <img class="logo-img" @click="gotoPage('main')" src="@/assets/logo.png" />
          <h1 class="system-name">
            批产信息管理平台<span class="version"></span>
          </h1>

          <ul class="menu-list">
            <li
              class="btn-action menu-item"
              :class="{ active: currentMenu == 'maillist' }"
              @click="gotoPage('maillist')"
            >
              <img class="btn-icon" src="../../assets/icon/icon-contacts.png" />
              <span>通讯录</span>
            </li>
            <li
              class="btn-action menu-item"
              :class="{ active: currentMenu == 'product' }"
              @click="gotoPage('product')"
            >
              <img class="btn-icon" src="../../assets/icon/icon-manager.png" />
              <span>产品管理</span>
            </li>
            <li
              class="btn-action menu-item"
              :class="{ active: currentMenu == 'knowledge' }"
              @click="gotoPage('knowledge')"
            >
              <img
                class="btn-icon"
                src="../../assets/icon/icon-knowledge.png"
              />
              <span>知识库</span>
            </li>
          </ul>
        </div>
        <ul class="action-list">
          <li class="btn-action action-item" @click="logoutHandle">
            <img class="btn-icon" src="../../assets/icon/icon-logout.png" />
            <span>退出</span>
          </li>
          <li class="btn-action action-item" @click="showDialog = true">
            <img class="btn-icon" src="../../assets/icon/icon-setting.png" />
            <span>设置</span>
          </li>
          <li class="btn-action action-item role">
            <span>欢迎您，{{ userInfo.userName }}</span>
            <i class="el-icon-arrow-down" style="margin-left: 10px"></i>
          </li>
        </ul>
      </div>
    </header>
    <main class="layout-content">
      <router-view></router-view>
    </main>
    <update-password-dialog v-if="showDialog" @close="showDialog = false" />
  </div>
</template>

<script>
import UpdatePasswordDialog from "@/components/UpdatePasswordDialog.vue";

export default {
  components: { UpdatePasswordDialog },
  data() {
    return {
      showDialog: false,
      currentMenu: "main",
    };
  },
  computed: {
    userInfo() {
      return this.$store.getters.userInfo;
    },
  },
  watch: {
    $route(to) {
      this.currentMenu = to.name;
    },
  },
  mounted() {
    setTimeout(() => {
      if (this.$route.path == "/") {
        this.currentMenu = "home";
      } else {
        let paths = this.$route.path.split("/");
        console.log(paths);
        this.currentMenu =
          paths && paths.length > 0 ? paths[paths.length - 1] : "main";
      }
    }, 100);
  },
  methods: {
    logoutHandle() {
      this.$router.push({ name: "login" });
    },
    gotoPage(page) {
      let routeData = this.$router.resolve({
        name: page
      });
      window.open(routeData.href, '_blank')
    },
  },
};
</script>

<style lang="scss" scoped>
.layout {
  // min-width: 1900px;
  height: 100vh;
  // background: #dcdfe8;
  background: linear-gradient(0deg, #e7e9f2 0%, #e7e9f2 100%);
  overflow: auto;
}
.layout-header {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 86px; // 实际高度76px
  background: url("../../assets/bg-header.png") no-repeat;
  background-size: 100% auto;
  z-index: 10;
  // overflow: auto;

  .header-content {
    display: flex;
    align-items: center;
    justify-content: space-between;
    height: 76px;
  }

  .logo-img {
    margin-top: 8px;
    margin-left: 30px;
    float: left;
    cursor: pointer;
  }

  .system-name {
    float: left;
    // margin-top: 15px;
    margin-left: 14px;
    font-size: 28px;
    font-weight: 400;
    color: #f2f2f2;
    text-shadow: 0px 4px 6px rgba(2, 23, 78, 0.6);
  }

  .version {
    margin-left: 15px;
    font-size: 18px;
  }

  .btn-action {
    display: flex;
    justify-content: center;
    align-items: center;
    height: 40px;
    font-size: 16px;
    color: #e0e2f1;
    background: rgba(105, 128, 255, 0.2);
    border: 1px solid #457fff;
    border-radius: 3px;
    cursor: pointer;

    &.active,
    &:hover {
      background-color: #457fff;
    }
  }
  .btn-icon {
    margin-right: 10px;
  }

  .menu-list {
    float: left;
    // margin-top: 15px;
    margin-left: 70px;

    .menu-item {
      float: left;
      // width: 160px;
      padding: 0 20px;
      margin-right: 20px;
    }
  }

  .action-list {
    float: right;
    // margin-top: 15px;
    margin-right: 16px;

    .action-item {
      float: right;
      width: 130px;
      margin-left: 10px;
    }

    .action-item.role {
      width: auto;
      padding: 0 24px;
    }
  }
}

.layout-action {
  height: 58px;
  box-shadow: 0px 3px 8px 0px rgba(122, 128, 159, 0.1);
}

.layout-content {
  margin-top: 76px;
}
</style>
